from utils.ListNode import ListNode

class Solution(object):
    def splitListToParts(self, root, k):
        cur = root
        for N in range(k):
            if not cur:
                break
            cur = cur.next
        width, remainder = divmod(N, k)

        ans = []
        cur = root
        for i in range(k):
            head = cur
            for j in range(width + (i < remainder) - 1):
                if cur:
                    cur = cur.next
            if cur:
                cur.next, cur = None, cur.next
            ans.append(head)
        return ans


if __name__ == "__main__":
    # 创建链表
    node = ListNode()
    node.append(1)
    node.append(2)
    node.append(3)
    node.print_list()

    # 测试Solution
    obj = Solution()
    res = obj.splitListToParts(node.head, 5)
    print(res)